<table class="purchase_content">
  <%= render collection: line_items, partial: 'spree/shared/purchased_items_table/line_item', as: :line_item %>
  <%= render 'spree/shared/purchased_items_table/subtotal', order: order %>
  <% if order.line_item_adjustments.exists? %>
    <% if order.all_adjustments.promotion.eligible.exists? %>
      <% order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
        <tr>
          <td></td>
          <td>
            <p class="f-fallback purchase_total purchase_total--label">
              <%= Spree.t(:promotion) %>:
            </p>
            <p class="f-fallback purchase_total--name purchase_total--label">
              <%= label %>
            </p>
          </td>
          <td class="purchase_total-col">
            <p class="f-fallback purchase_total">
              <%= Spree::Money.new(adjustments.sum(&:amount), currency: order.currency) %>
            </p>
          </td>
        </tr>
      <% end %>
    <% end %>
  <% end %>
  <% order.shipments.group_by { |s| s.selected_shipping_rate&.name }.each do |name, shipments| %>
    <tr>
      <td></td>
      <td>
        <p class="f-fallback purchase_total purchase_total--label">
          <%= Spree.t(:shipping) %>:
        </p>
        <p class="f-fallback purchase_total--name purchase_total--label">
          <%= name %>
        </p>
      </td>
      <td class="purchase_total-col">
        <p class="f-fallback purchase_total">
          <%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %>
        </p>
      </td>
    </tr>
  <% end %>
  <% if order.additional_tax_total != 0 %>
    <tr>
      <td></td>
      <td>
        <p class="f-fallback purchase_total purchase_total--label">
          <%= Spree.t(:tax) %>:
        </p>
      </td>
      <td class="purchase_total-col">
        <p class="f-fallback purchase_total">
          <%= order.display_additional_tax_total.to_html %>
        </p>
      </td>
    </tr>
  <% end %>
  <% order.adjustments.eligible.each do |adjustment| %>
    <% next if (adjustment.source_type == 'Spree::TaxRate') || (adjustment.amount == 0) %>
    <%= render 'spree/shared/purchased_items_table/adjustment', adjustment: adjustment, order: order %>
  <% end %>
  <%= render 'spree/shared/purchased_items_table/total', order: order %>
</table>
